#include "RequestCodec.h"

RequestCodec::RequestCodec() {}

RequestCodec::RequestCodec(std::string encstr) { initMessage(encstr); }

RequestCodec::RequestCodec(RequestInfo const* info) { initMessage(info); }

void RequestCodec::initMessage(std::string encstr) { this->m_encStr = encstr; }

void RequestCodec::initMessage(RequestInfo const* info) {
  this->m_msg.set_cmdtype(info->cmdType);
  this->m_msg.set_clientid(info->clientID);
  this->m_msg.set_serverid(info->serverID);
  this->m_msg.set_sign(info->sign);
  this->m_msg.set_data(info->data);
}

std::string RequestCodec::encodeMsg() { 
	std::string output;
	this->m_msg.SerializeToString(&output);
	return output;
}

void* RequestCodec::decodeMsg() {
	this->m_msg.ParseFromString(this->m_encStr);
	return &(this->m_msg);
}

RequestCodec::~RequestCodec() {}
